library(dplyr)##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(tidyverse)## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ tibble 3.1.5 ✓ purrr 0.3.4
## ✓ tidyr 1.1.4 ✓ stringr 1.4.0
## ✓ readr 2.0.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(stringr)
library(wesanderson)dat3 <- read.csv("~/Documents/GitHub/honours-project/1-42 LR.csv")
dat3$bee_id <- as.factor(dat3$bee_id)
dat3$number <- as.factor(dat3$number)
# Split the data into 2 groups: small/ big
dat3.small <- dat3 %>%
filter(dat3$number == "small")
dat3.big <- dat3 %>%
filter(dat3$number == "large")
# add a new column or LR
dat3.small.LR <- dat3.small %>%
mutate(LR = ifelse(str_detect(choice, "1"), "L", "R")) # Create a new column for S/B
dat3.big.LR <- dat3.big %>%
mutate(LR = ifelse(str_detect(choice, "1"), "L", "R"))
# split into small L/R and big L/R
dat3.small.L <- dat3.small.LR %>% # small L
filter(dat3.small.LR$LR == "L")
dat3.small.L.prop <- dat3.small.L %>% # small L proportion for individual
group_by(bee_id) %>%
summarise(prop = length(LR)/10)
as.numeric(unlist(dat3.small.L.prop))## [1] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0
## [16] 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0
## [31] 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 0.3 0.3 0.6
## [46] 0.7 0.4 0.3 0.6 0.7 0.7 0.5 0.5 0.7 0.2 0.5 0.5 0.2 0.3 0.4
## [61] 0.4 0.2 0.3 0.3 0.2 0.7 0.8 0.6 0.8 0.3 0.7 0.5 0.2 0.7 0.7
## [76] 0.5 0.2 0.4 0.9 0.3 0.4 0.6 0.1 0.7
small.L.mean <- mean(dat3.small.L.prop$prop) # mean for small L
small.L.sd <- sd(dat3.small.L.prop$prop) # sd for small L
dat3.small.R <- dat3.small.LR %>% # small R
filter(dat3.small.LR$LR == "R")
dat3.small.R.prop <- dat3.small.R %>% # small R proportion for individual
group_by(bee_id) %>%
summarise(prop = length(LR)/10)
as.numeric(unlist(dat3.small.R.prop))## [1] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0
## [16] 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0
## [31] 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 0.7 0.7 0.4
## [46] 0.3 0.6 0.7 0.4 0.3 0.3 0.5 0.5 0.3 0.8 0.5 0.5 0.8 0.7 0.6
## [61] 0.6 0.8 0.7 0.7 0.8 0.3 0.2 0.4 0.2 0.7 0.3 0.5 0.8 0.3 0.3
## [76] 0.5 0.8 0.6 0.1 0.7 0.6 0.4 0.9 0.3
small.R.mean <- mean(dat3.small.R.prop$prop) # mean for small R
small.R.sd <- sd(dat3.small.R.prop$prop) # sd for small R
### BIG ###
dat3.big.L <- dat3.big.LR %>% # big L
filter(dat3.big.LR$LR == "L")
dat3.big.L.prop <- dat3.big.L %>% # big L proportion for individual
group_by(bee_id) %>%
summarise(prop = length(LR)/10)
as.numeric(unlist(dat3.big.L.prop))## [1] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 14.0 15.0 16.0
## [16] 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0
## [31] 32.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 0.3 0.4 0.5 0.5 0.3
## [46] 0.5 0.6 0.5 0.6 0.6 0.5 0.5 0.4 0.3 0.3 0.3 0.2 0.4 0.4 0.1
## [61] 0.2 0.3 0.3 0.5 0.5 0.5 0.1 0.5 0.3 0.5 0.1 0.3 0.2 0.3 0.3
## [76] 0.2 0.3 0.3 0.1 0.4
big.L.mean <- mean(dat3.big.L.prop$prop) # mean for big L
big.L.sd <- sd(dat3.big.L.prop$prop) # sd for big L
dat3.big.R <- dat3.big.LR %>% # big R
filter(dat3.big.LR$LR == "R")
dat3.big.R.prop <- dat3.big.R %>% # big R proportion for individual
group_by(bee_id) %>%
summarise(prop = length(LR)/10)
as.numeric(unlist(dat3.big.R.prop))## [1] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0
## [16] 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0
## [31] 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 0.7 0.6 0.5
## [46] 0.5 0.7 0.5 0.4 0.5 0.4 0.4 0.5 0.5 1.0 0.6 0.7 0.7 0.7 0.8
## [61] 0.6 0.6 0.9 0.8 0.7 0.7 0.5 0.5 0.5 0.9 0.5 0.7 0.5 0.9 1.0
## [76] 0.7 0.8 0.7 0.7 0.8 0.7 0.7 0.9 0.6
big.R.mean <- mean(dat3.big.R.prop$prop) # mean for big R
big.R.sd <- sd(dat3.big.R.prop$prop) # sd for big Rdat4 <- read.csv("~/Documents/GitHub/honours-project/28-42 UD.csv")
dat4$BEEID <- as.factor(dat4$BEEID)
dat4$NUMBER <- as.factor(dat4$NUMBER)
dat4$UD <- ifelse(str_detect(dat4$CHOICE, "1"), "U", "D")
# Split the data into 2 groups: small/ big
dat4.small <- dat4 %>%
filter(dat4$NUMBER == "small")
dat4.big <- dat4 %>%
filter(dat4$NUMBER == "large")
# split into small L/R and big L/R
dat4.small.U <- dat4.small %>% # small U
filter(UD == "U")
dat4.small.U.prop <- dat4.small.U %>% # small U proportion for individual
group_by(BEEID) %>%
summarise(prop = length(UD)/10)
as.numeric(unlist(dat4.small.U.prop))## [1] 1.0 2.0 3.0 4.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 0.5
## [16] 0.7 0.2 0.9 0.5 0.2 0.4 0.7 0.8 0.6 0.1 0.5 0.8 0.8
small.U.mean <- mean(dat4.small.U.prop$prop) # mean for small U
small.U.sd <- sd(dat4.small.U.prop$prop) # sd for small U
#------------------------------------------#
dat4.small.D <- dat4.small %>% # small D
filter(UD == "D")
dat4.small.D.prop <- dat4.small.D %>% # small D proportion for individual
group_by(BEEID) %>%
summarise(prop = length(UD)/10)
as.numeric(unlist(dat4.small.D.prop))## [1] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0
## [16] 0.5 0.3 0.8 0.1 1.0 0.5 0.8 0.6 0.3 0.2 0.4 0.9 0.5 0.2 0.2
small.D.mean <- mean(dat4.small.D.prop$prop) # mean for small D
small.D.sd <- sd(dat4.small.D.prop$prop) # sd for small D
#-----------------------------------------#
dat4.big.U <- dat4.big %>% # big U
filter(UD == "U")
dat4.big.U.prop <- dat4.big.U %>% # bog U proportion for individual
group_by(BEEID) %>%
summarise(prop = length(UD)/10)
as.numeric(unlist(dat4.big.U.prop))## [1] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0
## [16] 0.8 0.9 0.3 0.7 0.3 0.5 0.9 0.3 0.4 0.8 0.6 0.3 0.1 0.7 0.3
big.U.mean <- mean(dat4.big.U.prop$prop) # mean for big U
big.U.sd <- sd(dat4.big.U.prop$prop) # sd for big U
#---------------------------------------#
dat4.big.D <- dat4.big %>% # small D
filter(UD == "D")
dat4.big.D.prop <- dat4.big.D %>% # small D proportion for individual
group_by(BEEID) %>%
summarise(prop = length(UD)/10)
as.numeric(unlist(dat4.big.D.prop))## [1] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0
## [16] 0.2 0.1 0.7 0.3 0.7 0.5 0.1 0.7 0.6 0.2 0.4 0.7 0.9 0.3 0.7
big.D.mean <- mean(dat4.big.D.prop$prop) # mean for small D
big.D.sd <- sd(dat4.big.D.prop$prop) # sd for small D## data for plotting bar plot
R <- data.frame(number = rep(c("small","big"), each = 2),
direction = rep(c("L","R"), times = 2),
proportion = c(0.50,0.50, 0.29,0.71),
mean = c(small.L.mean, small.R.mean, big.L.mean, big.R.mean),
sd = c(small.L.sd, small.R.sd, big.L.sd, big.R.sd))
# barplot
exp1.LR <- ggplot(R, aes(x = number, y = proportion, fill = direction)) +
geom_bar(stat = "identity", position = "dodge") +
geom_errorbar(aes(ymin = mean-sd, ymax = mean+sd), width=.2,
position=position_dodge(.9)) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1, suffix = NULL), limits = c(0,1)) +
geom_hline(yintercept = 0.5, linetype = "dashed", colour = "grey") +
labs (x= "Number Tests", y = "Proportion of choosing L or R in two number tests") +
scale_fill_manual(values = wes_palette("GrandBudapest1", n = 2)) +
theme(panel.background = element_blank(),
axis.line = element_line(colour = "black"))
print(exp1.LR)## data for plotting bar plot
U <- data.frame(number = rep(c("small","big"), each = 2),
direction = rep(c("U","D"), times = 2),
proportion = c(0.51,0.49, 0.53,0.47),
mean = c(small.U.mean, small.D.mean, big.U.mean, big.D.mean),
sd = c(small.U.sd, small.D.sd, big.U.sd, big.D.sd))
# barplot
ggplot(U, aes(x = number, y = proportion, fill = direction)) +
geom_bar(stat = "identity", position = "dodge") +
geom_errorbar(aes(ymin = mean-sd, ymax = mean+sd), width=.2,
position=position_dodge(.9)) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1, suffix = NULL), limits = c(0,1)) +
labs (x= "Number Tests", y = "Proportion of choosing U or D in two number tests") +
scale_fill_manual(values = wes_palette("GrandBudapest2", n = 2)) +
geom_hline(yintercept = 0.5, linetype = "dashed", colour = "grey") +
theme(panel.background = element_blank(),
axis.line = element_line(colour = "black"))template provided by Bug of the week